package com.huawei.od.c.easy.t3;

public class T3 {
    public static void main(String[] args) {
        t3(9);
        System.out.println("------------------------------------");
        t3(10);
        System.out.println("------------------------------------");
        t3(11);
        System.out.println("------------------------------------");
        t3(12);
        System.out.println("------------------------------------");
        t3(13);
        System.out.println("------------------------------------");
        t3(14);
        System.out.println("------------------------------------");
        t3(15);
        System.out.println("------------------------------------");
    }

    private static void t3(int num) {
        int result = 1;
        int count = 0;
        while (true) {
            int x = result - 1;
            int sumX = sumZeroToX(x);
            if (result > num || sumX > num) {
                break;
            }
            int left = num - sumX;
            if (left % result == 0) {
                count++;
                int numMin = left / result;
                doPrint(num, result, numMin);
            }
            result++;
        }
        System.out.println("Result:" + count);
    }

    private static void doPrint(int sum, int count, int begin) {
        StringBuilder sb = new StringBuilder();
        sb.append(sum).append("=");
        int c = 0;
        while (true) {
            int num = c + begin;
            if (c >= count-1) {
                sb.append(num);
                break;
            }
            sb.append(num).append("+");
            c++;
        }
        System.out.println(sb.toString());
    }

    private static int sumZeroToX(int x) {
        return (1 + x) * x / 2;
    }

}
